<?php include("head.php");
include_once("paging_function.php");
?>
<script language="JavaScript">

function changeUrl(indexalpha)
{
var url='admgt.php?index='+indexalpha;
window.location=url;
}
</script>

<script language="javascript" src="js/contactpopcalendar.js"></script>

<?php
$statustype=$_POST['selectstatus'];
/////////////////////////////////PAGING /////////////////
 	if(isset($_GET['page']) && $_GET['page']!='')
		{
		
			$page = $_GET['page'];
		}
	else
		{
			$page = 0;
		}
$limit=$adminpagelimit;
/////////////////////////////////////////////////////////////////	
?>
<?php
////////////////////////////////////////////    Block_---- DELETE  ///////////
if(isset($_POST['Submit']))
{
	$del=$_POST['del'];
	$no=count($del);
	if($no>0)
	{
	for($i=0;$i<$no;$i++)
	{

	   mysql_query("DELETE FROM ".ADVERTISEMASTER." WHERE advertiseId= '".$del[$i]."' ");
	    mysql_query("DELETE FROM ".ADVDETAILS." WHERE advertiseId= '".$del[$i]."' ");

	}
	echo '<script>window.location="admgt.php?dlt=1"</script>';
	}
	$block=$_POST['count_UPDATE'];
	if($_POST['count_UPDATE']>0)
	{
		for($no_up=0; $no_up<$block;$no_up++)
		{
			if(isset($_POST['block'.$no_up]))
			{
				mysql_query("UPDATE ".ADVERTISEMASTER."  set advertiseStatus='N' WHERE advertiseId='".$_POST['block'.$no_up]."'");
				//echo "UPDATE ".SITEMASTER."  set status='N' WHERE advertiseId='".$_POST['block'.$no_up]."'";
			}
			else
			{
				mysql_query("UPDATE ".ADVERTISEMASTER."  set advertiseStatus='Y' WHERE advertiseId='".$_POST['block_hid'.$no_up]."'");
				//echo "UPDATE ".SITEMASTER."  set status='Y' WHERE advertiseId='".$_POST['block_hid'.$no_up]."'";
			}
		}
	echo '<script>window.location="admgt.php?page='.$_GET['page'].'&loop='.$_GET['loop'].'&start='.$_GET['start'].'&blk=1"</script>';
	}
}
?>

<?php
$search="SELECT * FROM ".ADVERTISEMASTER.",".SITEUSERS." WHERE ".ADVERTISEMASTER.".siteuserId =".SITEUSERS.".siteuserId ";


	if(isset($_POST['usersearch']) && $_POST['usersearch']!="")

	{
		
		$param="typesearch=".$_REQUEST['typesearch'];
		$search.= " AND  username LIKE'".$_REQUEST['usersearch']."%'";

	}

	if(isset($_POST['typesearch']) && $_POST['typesearch']!="" )

	{

		$param="typesearch=".$_REQUEST['typesearch'];
		$search.= " AND  adType LIKE '".$_REQUEST['typesearch']."%'";

	}

	if(isset($_POST['titlesearch']) && $_POST['titlesearch']!="")

	{

		$param="titlesearch=".$_REQUEST['titlesearch'];
		$search.= " AND adTitle LIKE '".$_REQUEST['titlesearch']."%'";
 
 	}
	if(isset($_POST['startdate']) && $_POST['startdate']!="")

	{

		$param="startdate=".$_REQUEST['startdate'];
		$search.= " AND startDate = '".$_REQUEST['startdate']."'";
 
 	}
	if(isset($_POST['selectstatus']) && $_POST['selectstatus']!="")

	{
		$param="selectstatus=".$_REQUEST['selectstatus'];
 		$search.= " AND advertiseStatus = '".$_REQUEST['selectstatus']."'";
 
 	}
	if($_REQUEST['index']!='' && isset($_REQUEST['index']))

	{

		$param="index=".$_REQUEST['index'];
		$search.=" and username like'".$_REQUEST['index']."%'";
	
    	}
	else 
	{

	$search.="ORDER BY advertiseId  DESC";

 	}

	$search.=" limit $page,$limit";	

	$searchquery=mysql_query($search) or die('error1'.mysql_error());
	
?>
<!--<fieldset>
<legend class="LEGEND"><b>AD  MANAGEMENT</b></legend>-->
 <table width="100%" border="0" cellspacing="0" cellpadding="3"  style="border:1px solid #666666">

 <tr><td>&nbsp;</td></tr>

 <tr><td>&nbsp;</td></tr>

 <tr><td>
 <table width="100%" border="0" cellspacing="0" cellpadding="3">
 <tr><td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
		<tr> 
			<td height="15" colspan="2" align="center" style="color:#000000;font-size:12px;">
				<font color="#000000"><strong> ADVERTISEMENT  MANAGEMENT </strong></font>
			</td> 
		</tr>

	<tr style="display:" id="editWin">
		<td colspan='2' id="ShowMsg">
		</td>
	</tr>
	<?php 
	if((isset($_GET['blk']) && $_GET['blk']==1) || (isset($_GET['dlt']) && $_GET['dlt']==1) || (isset($_GET['inst']) && $_GET['inst']==1) || (isset($_GET['updt']) && $_GET['updt']==1) )
	{
	?>
	<tr>
	
		<td colspan='2' style="color:#FF0000">
		<?php 
		if(isset($_GET['blk']) && $_GET['blk']==1)
		{
		echo $msg1="Value Blocked/Unblocked Successfully!!!";
		}
		if(isset($_GET['dlt']) && $_GET['dlt']==1)
		{
		echo $msg1="Value Deleted Successfully!!!";
		}
		
		?></td>
	</tr>
	<?php
	}
	?>
</table>



	<table width="100%" border="0" cellspacing="0" cellpadding="3" class="tabbod">
	<?php
	if(isset($_REQUEST['action']))
		{
			$sql="SELECT username,adType,email,startDate,endDate,dailyBudget,maxBudget,adDisplayType,adSiteUrl,networkName FROM ".SITEMASTER.",".SITEUSERS.",".ADVERTISEMASTER.",".ADVDETAILS.",".NETWORKMASTER." WHERE  ".ADVERTISEMASTER.".siteuserId=".SITEUSERS.".siteuserId AND ".ADVERTISEMASTER.".advertiseId=".ADVDETAILS.".advertiseId  AND ".ADVDETAILS.".networkId= ".NETWORKMASTER.".networkId AND ".ADVDETAILS.".adsiteId=".SITEMASTER.".adsiteId AND  ".ADVERTISEMASTER.".advertiseId ='".$_REQUEST['advertiseId']."'";
			

			$QUERY= mysql_query($sql) or die('admgt edit '.mysql_error());
			$fetch=mysql_fetch_array($QUERY);

	?>
<tr><td colspan="6" id="edit_section" style="display:;">
<fieldset>
	<legend class="LEGEND"> <?php echo ucfirst($_REQUEST['action']);?>Ad </legend>
	
		<table width="100%" border="0" align="center" cellpadding="5" cellspacing="0">
			<tr>
				<td width="27%" align="left" id="admin_text">User Name</td>
				<td width="2%" align="left">::</td>
				<td width="71%" align="left"><?php echo $fetch['username'];?></td>
			</tr>
			<tr>
				<td width="27%" align="left" id="admin_text">User Email</td>
				<td width="2%" align="left">::</td>
				<td width="71%" align="left"><?php echo $fetch['email'];?></td>
			</tr>
			<tr>
				<td width="27%" align="left" id="admin_text">Network Name</td>
				<td width="2%" align="left">::</td>
				<td width="71%" align="left"><?php echo $fetch['networkName'];?></td>
			</tr>
			<tr>
				<td width="27%" align="left" id="admin_text">Site URL</td>
				<td width="2%" align="left">::</td>
				<td width="71%" align="left"><?php echo $fetch['adSiteUrl'];?></td>
			</tr>
			
			<tr>
				<td width="27%" align="left" id="admin_text">Ad Display Type</td>
				<td width="2%" align="left">::</td>
				<td width="71%" align="left"><?php echo $fetch['adDisplayType'];?></td>
			</tr>
		
			<tr>
				<td width="27%" align="left" id="admin_text">Start Date</td>
				<td width="2%" align="left">::</td>
				<td width="71%" align="left"><?php echo $fetch['startDate'];?></td>
			</tr>
			<tr>
				<td width="27%" align="left" id="admin_text">End Date</td>
				<td width="2%" align="left">::</td>
				<td width="71%" align="left"><?php echo $fetch['endDate'];?></td>
			</tr>
			<tr>
				<td width="27%" align="left" id="admin_text">Daily Budget</td>
				<td width="2%" align="left">::</td>
				<td width="71%" align="left">$<?php echo $fetch['dailyBudget'];?></td>
			</tr>
			<tr>
				<td width="27%" align="left" id="admin_text">Max Budget</td>
				<td width="2%" align="left">::</td>
				<td width="71%" align="left">$<?php echo $fetch['maxBudget'];?></td>
			</tr>
			<tr>
				<td align="center">&nbsp;</td>
				<td align="center">&nbsp;</td>
				<td align="left">
				<input type="button" value="Close" name="close_frm" id="close_frm" onClick="window.location='admgt.php'" /></td>
			</tr>
		</table>	

</fieldset>
	<?php } ?>
</td></tr>
	
	
	<tr>
	
		<td colspan="8" align="center" style="color:#000000;font-size:12px;"><p><strong style="font-weight: 400">Click on the alphabets to browse User Name</strong><strong style="font-weight: 400"><br>&nbsp;</strong></p><?php include_once("search_alphabets.php");?></td>
	
	</tr>
	<tr>
		<td colspan="8">
			<form name="FieldSearch" id="FieldSearch" method="POST">
			<table width="100%" cellpadding="0" cellspacing="0" border="0">
				<tr>
					<td>Search By </td>
					<td valign="middle">Ad Type :<input type="text" name="typesearch" value="<?php echo $_POST['typesearch']; ?>" size="10"></td>
					<td valign="middle">User Name :<input type="text" name="usersearch" value="<?php echo $_POST['usersearch']; ?>" size="10">&nbsp;</td>					
					<td valign="middle">Ad Title :<input type="text" name="titlesearch" value="<?php echo $_POST['titlesearch']; ?>" size="10">&nbsp;</td>
					<td valign="middle">StartDate<input name="startdate" type="text" class="inplogin" id="startdate" value="<?php echo $_REQUEST['startdate'];?>" size="10" >
		&nbsp;&nbsp;<img src="images/calendar.gif" width="19" height="15" onClick="popUpCalendar(this, document.all.startdate, 'yyyy-mm-dd');" align="absmiddle" /></td>
					<td class="SMALL"> Ad Status:<select name="selectstatus" class="SMALL" >
					<option value="" selected="selected">Ad Status </option>
					<option value="Y"  <?php if($statuetype == "Y") echo 'selected'; ?>>Active</option>
					<option value="N"  <?php if($statustype == "N") echo 'selected'; ?>>Inactive</option>
					<option value="B" <?php if($statustype == "B") echo 'selected'; ?>>Block</option>
					</select>&nbsp;&nbsp;<input type="submit" name="search" value="Search">
					</td>
					
				</tr>
				<tr><td colspan="6"><a href="admgt.php" style="color:#000000;font-size:12px;">View All</a></td>
				
			</table>
			</form>
		</td>
	</tr>
<?php

  if(mysql_num_rows($searchquery)>0)
  	{
	
	?><form name="form_admin_management" action="" method="post">
		<tr bgcolor="#6F8DBC">
			<td width="7%" height="28" style="color:#ffffff;font-size:12px;"><strong>S.No</strong></td>
			<td width="10%" align="left" valign="middle" style="color:#ffffff;font-size:12px;"><strong>Ad Type</strong> </td>
			<td width="13%" valign="middle" style="color:#ffffff;font-size:12px;"><strong>User Name</strong></td>
			<td width="28%" valign="middle" style="color:#ffffff;font-size:12px;"><strong>Ad Title</strong></td>
			<td width="20%" valign="middle" style="color:#ffffff;font-size:12px;"><strong>Start Date</strong></td>
			<td width="5%" align="center" valign="middle" style="color:#ffffff;font-size:12px;"><strong>Details</strong></td>
			<td width="5%" align="center" valign="middle" style="color:#ffffff;font-size:12px;"><strong>Status</strong></td>
			<td width="5%" align="center" valign="middle" style="color:#ffffff;font-size:12px;"><strong>Delete</strong></td>
	</tr>
	<?php 
			$count=0;
			$sno=1;
			$loop=0;
	while($searcharray=mysql_fetch_array($searchquery))
		{
			$loop++;
			if($loop == 1)
			$bgcolor = "#F0F0FF";
			else 
			$bgcolor = "#CCCCFF";
	?>
		<tr bgcolor="<?php echo $bgcolor; ?>">
			<td style="color:#000000;font-size:12px;" width="5%"><strong><?php echo $sno+$_GET['page'];//echo $searcharray['usercode']; ?></strong></td>
			<td align="left" valign="middle" style="color:#000000;font-size:12px;" width="15%"><?php echo ($searcharray['adType']); ?></td>
			<td align="left" valign="middle" style="color:#000000;font-size:12px;" width="20%"><?php echo ($searcharray['username']); ?></td>
			<td align="left" valign="middle" style="color:#000000;font-size:12px;" width="25%"><?php echo ($searcharray['adTitle']); ?></td>
			<td align="left" valign="middle" style="color:#000000;font-size:12px;" width="15%"><?php echo ($searcharray['startDate']); ?></td>
			<td align="center" valign="middle" width="10%"><a href="admgt.php?action=details&advertiseId=<?php echo $searcharray['advertiseId'];?>" ><img src="images/edit_icon.gif" border="0"/></a></td>
			<td align="center" valign="middle" width="10%"><input type="checkbox" name="block<?php echo $count; ?>" value="<?php echo $searcharray['advertiseId']; ?>" <?php if($searcharray[`adsite_master`.'advertiseStatus']=='N') echo "checked";?>>
				<input type="hidden" name="block_hid<?php echo $count; ?>" value="<?php echo $searcharray['advertiseId'];?>">&nbsp;<br><strong> <?php 										if($searcharray['advertiseStatus']=='Y')
										{
											echo "Active";
										}
									if($searcharray['advertiseStatus']=='N')
										{
											echo "InActive";
										}

									if($searcharray['advertiseStatus']=='B')
										{
											echo "Blocked";
										}
										
										?>
				</strong></td>
			<td align="center" valign="middle"><input type="checkbox" name="del[]" value="<?php echo $searcharray['advertiseId'];?>"></td>
	</tr>
			<?php 
			$count++;
			$sno++;
			if($loop == 2)
				{
				$loop = 0;
				}	
		}
			?>
		<tr>
			<td colspan="4">&nbsp;</td>
			<td colspan="4" align="right"><input type="hidden" name="count_UPDATE" value="<?php echo $count; ?>">
			<input type="submit" name="Submit" value="Update"></td>
		</tr>
		<tr>
			<td colspan="8" align="center" style="color:#FF0000"><?php echo paging($search,$page,$limit,'',$param);?></td>
		</tr>
		<?php
	
	}
	
	else
	
	{
	
	?>
	<tr bgcolor="#6F8DBC">
		<td style="color:#ffffff;font-size:12px;"><strong>S.No</strong></td>
		<td  align="center" style="color:#ffffff;font-size:12px;"><strong>Site Type</strong></td>
		<td style="color:#ffffff;font-size:12px;"><strong>User Name</strong></td>
		<td style="color:#ffffff;font-size:12px;"><strong>Site URL</strong></td>
		<td  valign="middle" style="color:#ffffff;font-size:12px;"><strong>Publish Date</strong></td>
		<td  align="center" style="color:#ffffff;font-size:12px;"><strong>Details</strong></td>
		<td align="center" style="color:#ffffff;font-size:12px;"><strong>Status</strong></td>
		<td align="center" style="color:#ffffff;font-size:12px;"><strong>Delete</strong></td>
      </tr>
    <tr>
      <td colspan="8" align="left">&nbsp;&nbsp;&nbsp;<strong><font color="#FF0000" class="DISPLAYMESSAGES">No Result Found!</font></strong></td>
    </tr>
    <?php

  	}

  ?>
</form>
  </table>
  </td>
</tr>
</table>
<!--</fieldset>-->
</td>
</tr>
</table>
<?php 

include("foot.php");?>
